package fr.inria.phoenix.scenario.bwsnfirefighting.framework.distributed.alarmmanager;

import java.util.Iterator;
import java.util.Arrays;

import fr.inria.diagen.core.exception.InvocationException;
import fr.inria.diagen.core.service.local.Service;


public class LightComposite implements Iterable<LightProxy> {
    private LightProxy[] proxys;
    private Service abstractComponent;
    
    public LightComposite(LightProxy[] proxys, Service abstractComponent) {
      this.proxys=proxys;
      this.abstractComponent=abstractComponent;
    }
    
    public Iterator<LightProxy> iterator() {
        return Arrays.asList(proxys).iterator();
    }

    /**
     * 
     *
     * ! Composite Style
     */
    public void deactivate() {
      for(LightProxy proxy : proxys) {
          try {
              proxy.deactivate();
          } catch (InvocationException e) {
              e.printStackTrace();
          }
      }
    }
    /**
     * 
     *
     * ! Composite Style
     */
    public void activate() {
      for(LightProxy proxy : proxys) {
          try {
              proxy.activate();
          } catch (InvocationException e) {
              e.printStackTrace();
          }
      }
    }


    public boolean isEmpty() {
     return proxys.length == 0;
    }

    public int size() {
      return proxys.length;
    }
    
    public LightProxy anyOne() {
      try {
        return proxys[0];
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
  }
}